package com.pro01.backend.service;

import com.pro01.backend.mapper.ForumMapper;
import com.pro01.backend.pojo.Forum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ForumService {

    @Autowired
    private ForumMapper forumMapper;

    // 创建板块(管理员)
    public void createForum(Forum forum) {
        int result = forumMapper.insertForum(forum);
        if (result == 0) {
            throw new RuntimeException("创建板块失败");
        }
    }

    // 查询所有板块(管理员)
    public List<Forum> getAllForums() {
        return forumMapper.selectAllForums();
    }

    // 删除板块(管理员)
    public void deleteForum(Long forumId) {
        int result = forumMapper.softDeleteForum(forumId);
        if (result == 0) {
            throw new RuntimeException("删除失败，板块可能不存在");
        }
    }

    // 编辑板块(管理员)
    public void updateForum(Forum forum) {
        int result = forumMapper.updateForum(forum);
        if (result == 0) {
            throw new RuntimeException("更新失败，板块可能不存在");
        }
    }

    /**
     * 下面是所有用户的板块接口
     */

    // 用户查看所有板块的信息
    public List<Forum> getVisibleForums() {
        return forumMapper.selectVisibleForums();
    }




}
